package org.example.Spring.Bean;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Student {
    @Value("1")
    private int id;
    @Value("张三")
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @PostConstruct        //指定Bean实例完成初始化后调用的方法
    public void init(){
        System.out.println("Bean的初始化完成后，调用init()方法");
    }

    @PreDestroy          //指定Bean实例销毁前调用的方法
    public void destroy(){
        System.out.println("Bean销毁前调用destroy()方法");
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
